package Demo4;
class Message<T> {
    private T message ;
    public T getMessage() {
        return message;
    }
    public void setMessage(T message) {
        this.message = message;
    }
}
public class Test2 {
    //下界一般用来写入
    public static void funSuper(Message<? super Fruit> temp) {
        System.out.println(temp.getMessage());
        //此时可以修改添加的是Fruit或者Fruit的子类
        temp.setMessage(new Banana());//向上转型
        temp.setMessage(new Apple());
        //Fruit fruit = temp.getMessage();//此时不知道是那个父类
        System.out.println(temp.getMessage());
    }

    public static void main(String[] args) {
        Message<Food> message = new Message<>() ;
        Message<Fruit> message1 = new Message<>() ;
        funSuper(message);
        funSuper(message1);
    }
    public static void funExtend(Message<? extends Fruit> temp){
        System.out.println(temp.getMessage());
        //对于通配符的上界来说    是不可以修改元素的
        //temp.setMessage(new Banana());
        // temp.setMessage(new Apple());
        //向上转型
        Fruit fruit = temp.getMessage();
    }
    public static void main2(String[] args) {
        Message<Apple> message = new Message<>() ;
        message.setMessage(new Apple());
        Message<Banana> message1 = new Message<>() ;
        message1.setMessage(new Banana());
        funExtend(message);
        funExtend(message1);
    }
    public static void main1(String[] args) {
        Message<String> message = new Message<>() ;
        message.setMessage("666");
        fun(message) ;

        Message<Integer> message1 = new Message<>() ;
        message1.setMessage(666);
        fun(message);
    }
    //可以接受任意类型，但是由于不知道类型不能进行删改
    public static void fun(Message<?> temp){
    System.out.println(temp.getMessage());
    }
}
class Plate{

}
class Food extends Plate{
}
class Fruit extends Food {
}
class Apple extends Fruit {
}
class Banana extends Fruit {
}